import {Component, EventEmitter, OnInit, Output} from '@angular/core';
import {Globals} from '../../globals';
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
import {HttpClient} from '@angular/common/http';
import {BaseService} from '../../shared/service/base.service';
import {MyDateModel} from '../../models/my-date.model';

@Component({
  selector: 'app-toolbar',
  templateUrl: './toolbar.component.html',
  styleUrls: ['./toolbar.component.less']
})
export class ToolbarComponent implements OnInit {

  isMobile: boolean = Globals.isMobile();
  displayTime: boolean = false;
  validateForm!: FormGroup;
  isCollapse: false;
  date = null;
  selectedValue = null;
  show = false;

  startTime;
  endTime;

  constructor(
    private fb: FormBuilder,
    private baseService: BaseService
  ) {

  }

  ngOnInit(): void {
    this.validateForm = this.fb.group({
      name: [null, [Validators.required]],
      nickname: [null],
      required: [false],
      date: [null]
    });
  }


  submitForm(): void {
    for (const i in this.validateForm.controls) {
      this.validateForm.controls[i].markAsDirty();
      this.validateForm.controls[i].updateValueAndValidity();
    }
  }

  setDate(myDate: MyDateModel) {
    console.log(myDate)
    if (myDate.type == 'start') {
      this.startTime = myDate.date;
      console.log("this.startTime: " + this.startTime)
    } else {
      this.endTime = myDate.date;
      console.log("this.endTime: " + this.endTime)
    }

  }
}
